package com.samsungmobile.common;

import java.net.URL;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;

public class ConfOta {
	
	private static PropertiesConfiguration config;

	/**
	 * PropertiesConfiguration 
	 */
	public ConfOta() {
		try {
			
			ClassLoader cl = getClass().getClassLoader();
			URL url = cl.getResource("/ota.properties");
			/*
			String sURL = "D:\\02_Source\\samsungmobile\\prm\\conf\\ota.properties";
			URL url = new URL("file:///"+sURL);  
			*/	
			config = new PropertiesConfiguration(url);
			
			FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
			strategy.setRefreshDelay(500);
			config.setReloadingStrategy(strategy);
		} catch (ConfigurationException e) {
			Logger.printError(e);
		} catch (Exception e){
			
		}
	}

	/**
	 * Configuration key String 
	 * 
	 * @param strKey
	 * @return
	 */
	public static String getConf(String strKey) {
		if (config == null) {
			new ConfOta();
		}
		return config.getString(strKey, "");
	}

	public static String[] getArray(String strKey) {
		if (config == null) {
			new ConfOta();
		}
		return config.getStringArray(strKey);
	}	
	/**
	 * Configuration key boolean
	 * 
	 * @param strKey
	 * @return
	 */
	public static boolean getBoolean(String strKey) {
		if (config == null) {
			new ConfOta();
		}
		return config.getBoolean(strKey, false);
	}

	/**
	 * Configuration key int
	 * 
	 * @param strKey
	 * @return
	 */
	public static int getInt(String strKey) {
		if (config == null) {
			new ConfOta();
		}
		return config.getInt(strKey, -1);
	}

	/**
	 * Configuration key float
	 * 
	 * @param strKey
	 * @return
	 */
	public static float getFloat(String strKey) {
		if (config == null) {
			new ConfOta();
		}
		return config.getFloat(strKey, -1);
	}
	

}